x=int(input())
result=0

if x>999 and x<10000:
    a=x%10
    b=x//10%10
    c=x//100%10
    d=x//1000

    n=a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n
    
    n=b
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*b+a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=c
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*c+a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*c+b
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=100*c+10*b+a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=d
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*d+a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*d+b
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*d+b
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=100*d+10*b+a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=10*d+c
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=100*d+10*c+a
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=100*d+10*c+b
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n

    n=x
    prime=1
    for i in range(2,n):
        if n%i==0:
            prime=0
    if prime==1 and n>result:
        result=n
    
print(result)


